package com.sy.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sy.constant.JwtClaimsConstant;
import com.sy.context.BaseContext;
import com.sy.dto.UserLoginDTO;
import com.sy.dto.UserLoginDTO02;
import com.sy.dto.UserRegisterDTO;
import com.sy.pojo.User;
import com.sy.properties.JwtProperties;
import com.sy.result.PageResult;
import com.sy.result.Result;
import com.sy.service.OrdersService;
import com.sy.service.UserService;
import com.sy.utils.JwtUtil;
import com.sy.vo.OrdersVo;
import com.sy.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;


/**
 * 用户端-订单信息
 */
@Api(tags = "用户端-订单信息")
@RestController("userOrdersController")
@RequestMapping("/user/orders")
@Slf4j
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 用户端-查询订单信息
     * @return
     */
    @ApiOperation("用户端-查询订单信息")
    @GetMapping("/getOrdersByUser")
    public Result<List<OrdersVo>> getOrdersByUser() {
        Long userId = BaseContext.getCurrentId();
        log.info("当前用户的id:{}", userId);
        //根据用户id查询订单信息
        List <OrdersVo> ordersVoList= ordersService.getOrdersByUser(userId);

        return Result.success(ordersVoList);
    }

    /**
     * 用户端-删除订单信息
     * @param oid
     * @return
     */
    @ApiOperation("用户端-删除订单信息")
    @GetMapping("/deleteOrder")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "oid", value = "订单id", dataTypeClass = String.class)
    )
    public Result deleteOrder(String oid) {
        try {
            log.info("订单的id： {}", oid);
            ordersService.removeById(oid);
            return Result.success();
        } catch (Exception e) {
            throw new RuntimeException("订单删除失败");
        }
    }
}

